Sorry to add to the burgeoning noise on bookmarklets. I'm having trouble figuring out the right approach and some trouble coding it.
When the bookmarklet is activated, I want to
1) Open a popup as about:blank
2) Then change the URL to my external web page which handles the functionality of the bookmarklet
3) And in the process pass parameters to that page in the GET request
It should be easy right? Then why does #1 insist opening a new tab in Chrome rather than a popup?
<a href="javascript:(function(x) {var mypop=window.open('about:blank',config='height=200,width=400,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,directories=no,status=no');})('hello world');" >Click</a>
What am I doing wrong?
Thanks
You forgot the second parameter to window.open(), so your config string is being interpreted as window name, not settings. Use this:
window.open('about:blank', '_blank', '... your parameters ...');
Related
Hi guys,
I'running on wordpress
I made this:
http://imgur.com/Moc84HD.jpg
When I click on ''Click here to play the video clip'' it open a new (blank) window)
in HTML editor I wrote code:
Click here to play the video clip
But, I don't know how to implent this code into this blank space:
<script src='http://hqq.tv/player/hash.php?hash=244206211243244205241239213235211241'></script><script src='http://hqq.tv/player/script.php?width=720&height=450'>
I want this blank window will be looks like this:
http://imgur.com/MAcmjKe.jpg
Have you any solutions?
Thanks for help..
Have a nice day ! :)
In the window.open('', part you missed the first important part: the URL you should render. What you can do is, within your same web project, you can either:
a) Create a new, dynamic URL where you can pass the Video ID or something that let's you reference a single video and open that dynamic URL.
or, if you don't have a backend language, then you can...
b) Modify the content of the about:blank page you just opened by creating the popup, adding the HTML code inside and opening it. You'll still have an about:blank URL but you'll be actually seeing whatever content you put there. To do so, you should...
// Source: http://www.electrictoolbox.com/write-content-dynamic-javascript-popup/
var w = window.open('', '', 'width=400,height=400');
w.document.write('HTML content goes here, such as your script from hqq.tv');
w.document.close();
And modify the script accordingly.
PS: Be aware that, in order to write a script tag with Javascript, you'll have to split the tag in order to render it. Check this answer to see the problem and solution.
I am displaying an online internal website.
Upon clicking on a button "A" it processes a task, and goes to another HTML page. However, this direct address is like "hidden" (hard to explain).
For example, for each page I am accessing by simple button click, it's always the same URL (like http://host.com for every page I display from them).
I am using Firefox, and I need to know how to get the exact HTML address (or direct URL) used for displaying these full new pages. I managed to do it few months ago, but not anymore.
It will help me to automate some tasks and bashing programs. I am openned to any linux browser in case you find a way to help me. Thanks a lot.
it sounds like domain masking is used. you could check the source and see if a frame is being used on the page. the source should indicate the src of the frame, revealing the location of the page.
<frame src="page.html">
If the button uses window.open to navigate to the url, you could override that method and intercept the url there:
var oldOpen = window.open;
window.open = function(){
console.log(arguments[0]);
oldOpen.apply(window, arguments);
};
I am wondering whether it's possible to close a tab as soon as a new site has loaded, without having to use js on the new site. I basically want to close the tab when we receive any content from the new site.
I use this to trigger a click event which submits a form:
$('#target_attack').click();
I tried putting window.close() right after this, but the tab closed without having loaded the new site.
I also tried to pause the script for 3 seconds and then close the tab, but for some reasons the site then won't load.
I also thought about using sessions but this means I would have to use js on the other site too, which I want to avoid.
I hope you guys can help a little javascript noob C:
Thanks in advance!
Guessing you are using window.open to open it in a new tab.
var winPop = window.open(url);
$(winPop.document).ready(function() {
window.close();
});
If javascript didn't open the window, javascript cannot close the window. Otherwise, window.close() is what you use.
You can try to bypass this security restriction (bad plan), but I do not believe this works on newer versions of any browser:
window.top.opener=null;
window.close();
See the docs - Firefox: https://developer.mozilla.org/En/DOM:window.close, IE: http://msdn.microsoft.com/en-us/library/ms536367%28VS.85%29.aspx
I'm trying to create a simple click to print link for an image, and what I'd like to happen is when the link is clicked, a new window opens with the image, and the browser opens the print command dialogue box.
My question is whether this is possible just from a URL parameter, or from the anchor element on the initiating page? Or do I have to build a target page with javascript to do this?
Here's a sample of what I've got:
<p class="click-2-print">
Click here to print the map above
</p>
Obviously the code above will open the image in a new window, but still requires to user to hit Ctrl+P, Cmd+P or use the browser commands. My client wants the image to "just print" when the user clicks the link, so I'm trying to find the simplest way to accomplish this.
So is there any parameters or attributes that I can add to the above markup to accomplish what I have described?
You'll have to call window.print(). Perhaps something like this?
function printimage(){
var URL = "http://myimage.jpg";
var W = window.open(URL);
W.window.print();
}
Another option may be to put the image on a page that tells the browser to print when loaded. For example...
<body onload="window.print();">
<img src="/img/map.jpg">
</body>
Cody Bonney's answer will not work in certain browsers if the full url includes the image extension. The browser will automatically download it as soon as the new tab opens. You can get around this like so.
var url = scope.src;
var w = window.open('', '');
w.document.write('<html><head>');
w.document.write('</head><body >');
w.document.write('<img id="print-image-element" src="'+url+'"/>');
w.document.write('<script>var img = document.getElementById("print-image-element"); img.addEventListener("load",function(){ window.focus(); window.print(); window.document.close(); window.close(); }); </script>');
w.document.write('</body></html>');
w.window.print();
This will open a new page with the image, prompt the user to print, and after printing, close the new tab and reset focus to the original tab.
Disregard the scope.src that is angular specific code. Everything else should work as long as you provide your own url value from somewhere else
I would recommend you create a page in whatever language or framework you are working in that accepts a querystring argument for the image path, output that image in the document and have an onload / ready call to window.print(). Link to that instead of the image directly, and keep the target="_blank" and you should be set.
You have to call window.print() in javascript to trigger the browser print dialog. I'm pretty sure you can't trigger a print without user interaction unless you run a signed applet.
Hey Jag. Although its not exactly what you are looking to do, I did write this tutorial while I was working at a web design firm. You can probably rummage that code to get the link that prints the image. Basically what this code does it add a print button to the fancybox jquery plugin. I dont see why you couldnt just use the print part to add it to whatever you need. Hope it helps.
Add print ability to fancybox jquery plugin
I have the following javascript bookmarklet which opens a new popup window with a facebook post page in side of it.
javascript:var d=document,f='http://www.facebook.com/share',l=d.location,e=encodeURIComponent,p='.php?src=bm&v=4&i=1261526047&u='+e(l.href)+'&t='+e(d.title);1;try{if (!/^(.*\.)?facebook\.[^.]*$/.test(l.host))throw(0);share_internal_bookmarklet(p)}catch(z) {a=function() {if (!window.open(f+'r'+p,'sharer','toolbar=0,status=0,resizable=1,width=626,height=436'))l.href=f+p};if (/Firefox/.test(navigator.userAgent))setTimeout(a,0);else{a()}}void(0)
I just add that code into the URL of a shortcut link in my browser and it opens the facebook post page and passes the URL and some info about the page I am on to it.
I need to do a much simpler task. I need to get the URL of the page I am on and either open a new tab or even just use the tab I am in and then open a link like this
http://mydomain.com/labs/iframe_header.php?url= PUT THE CURRENT PAGES URL RIGHT HERE
As you can see I just need to make a bookmarklet that will take the page I am on and pass it into my sites page. Can anyone help me, I don't know much javascript at all, would greatly appreciate any help.
javascript: location.href = 'http://mydomain.com/labs/iframe_header.php?url=' + escape(location.href);
This will open in a new window, which will use a new tab if your browser is set up that way:
javascript: window.open('http://mydomain.com/labs/iframe_header.php?url=' + escape(location.href));