[Maptool 1.6.1] new links created with javascript don't work?

Thoughts, Help, Feature Requests, Bug Reports, Developing code for...

Moderators: dorpond, trevor, Azhrei

Forum rules
PLEASE don't post images of your entire desktop, attach entire campaign files when only a single file is needed, or generally act in some other anti-social behavior. :)
Post Reply
Findus
Kobold
Posts: 7
Joined: Mon May 23, 2016 4:51 am

[Maptool 1.6.1] new links created with javascript don't work?

Post by Findus »

I don't know if it's a bug or something that I did wrong, and I've not found anything related to it in the forums so I'm going to ask it in here.

I'm not a javascript expert but trying to make a new link inside a frame5 will make the link appear but it won't work.
Here's a very simple example,
the macro testJavaScriptLink :

Code: Select all

[h: sStr1 = macrolinkText("marioTest@this")]
[frame5("testFrame"):{
<!DOCTYPE html>
<html>
	<head>
	<script>
	[r:"
		function makeLink(elem){
			var oStr = elem.getAttribute('data-test');
			var oP = document.getElementById('idPar');
			var oA = document.createElement('a');
			oA.appendChild(document.createTextNode('New link!'));
			oA.title='A Title';
			oA.setAttribute('href',oStr);
			oP.appendChild(oA);  <!-- This doesn't work! -->

			var oA2 = document.getElementById('pre-Link');
			oA2.setAttribute('href',oStr); <!--we change the pre-existing link and it work-->
		}
	"]
	</script>
	<title> Something </title>
	</head>
	<body>
		<p><a href='#' onclick='makeLink(this);' data-test='[r:sStr1]'>Make a link</a></p>
		<p id='idPar'></p>
		<p><a href=# id='pre-Link'>This link does not work</a></p>
	</body>
</html>
}]
and the macro marioTest :

Code: Select all

[h:broadcast("Mario!")]
This code simply make a frame with 2 links, the first one call the javascript function, and the second one is broken on purpose.
The function will make a new link with a macro String, and also will put the same string in the broken link. The previously broken link will now work, while the newly made link won't work even with the same href.

Am i doing something wrong here?

Edit: Just for the sake of it I've even tried to pass the whole HTML code as a string and to write it in the frame using innerHTML, the link still appears but it still doesn't work.

Merudo
Giant
Posts: 228
Joined: Wed Jun 05, 2019 7:06 am

Re: [Maptool 1.6.1] new links created with javascript don't work?

Post by Merudo »

Thanks for the report. It's a bug, and will most likely be fixed in 1.7.

Here is the github issue: https://github.com/RPTools/maptool/issues/1638

Post Reply

Return to “MapTool”