Skip to content Skip to sidebar Skip to footer

Javascript Works As Bookmarklet But Not As Onclick Link

I use the following code to allow users to add a bookmarklet to browsers, which works perfectly, but if I try actually firing the code from a link on a page it does not. Is there s

Solution 1:

You have to:

  • replace %20 by space
  • remove javascript:

You could also use this function invocation trick !function( ...

Try this:

<a href="#" onclick="!function(d){var modal=document.createElement('iframe');modal.setAttribute('src','http://url.com/bm.html?url='+encodeURIComponent(window.location.href)+'&page_title='+document.title);modal.setAttribute('scrolling','no');modal.setAttribute('name','my_modal');modal.className='modal';document.body.appendChild(modal);var c=document.createElement('link');c.type='text/css';c.rel='stylesheet';c.href='//iframe.css';document.body.appendChild(c);}(document)">test</a>

Post a Comment for "Javascript Works As Bookmarklet But Not As Onclick Link"