I'm trying to open the link in popup, i've write this static html code :
<a href="" target="popup"
onclick="window.open('','popup','width=600,height=600');
return false;"> Open Link in Popup
</a>
this code works, it open the link in popup.
But, if i want to add this code in javascript (with jquery) like this :
$('#services').append("<li><a href='' target='popup' onclick='window.open('','popup','width=600,height=600'); return false;'>Open Link in Popup</a></li>");
The link is opened in new tab and not in popup.
Why ?
I'm trying to open the link in popup, i've write this static html code :
<a href="http://www.google." target="popup"
onclick="window.open('http://www.google.','popup','width=600,height=600');
return false;"> Open Link in Popup
</a>
this code works, it open the link in popup.
But, if i want to add this code in javascript (with jquery) like this :
$('#services').append("<li><a href='http://www.google.' target='popup' onclick='window.open('http://www.google.','popup','width=600,height=600'); return false;'>Open Link in Popup</a></li>");
The link is opened in new tab and not in popup.
Why ?
Share Improve this question asked Apr 18, 2017 at 9:18 Pasja95Pasja95 931 gold badge1 silver badge15 bronze badges 4- remove target='popup' from append clause and set href="#" – diavolic Commented Apr 18, 2017 at 9:21
- when i remove target, the current href is replaced by the new href – Pasja95 Commented Apr 18, 2017 at 9:24
-
set href="#" as i wrote before:
$('#services').append("<li><a href='#' onclick='window.open('http://www.google.','popup','width=600,height=600'); return false;'>Open Link in Popup</a></li>");
– diavolic Commented Apr 18, 2017 at 9:25 - Nothing happen when i set href to # – Pasja95 Commented Apr 18, 2017 at 9:29
3 Answers
Reset to default 2Check this example on jsfiddle - Problem is in quotes
$('#services').append("<a href='http://www.google.' target='popup' onclick=window.open('http://www.google.','popup','width=600,height=600'); return false;>Open Link in Popup</a>");
You missed to escape the quotes in onClick
of your jQuery. Update the script as below.
$('#services').append("<li><a href='http://www.google.' onclick=\"window.open('http://www.google.','popup','width=600,height=600'); return false;\">Open Link in Popup</a></li>");
Change your algorithm, instead of putting the javascript inside onclick, add a class or ID, with data-, so you can attach your jQuery event handler on that class/ID, and use the data to create new window. Imagine the data as data-destination="http://www.destination".
That should fix your problem.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744386318a4571681.html
评论列表(0条)