I have to decode response message from external web site (so, it's not possible to change the way they return messages), but it does not work in Fancybox modular pop-up where this page is loaded.
I'm using in such way (it works fine when page loads as "simple page", but not - when open this page using Fancybox jQyery plugin):
var response = JSON.parse(decodeURIComponent(h.url.param.get("response")));
the response looks like this:
response={%22Message%22%3a%22response+message+%3Ca+href%3d%27http%3a%2f%2fwww.linktosomeurl.com%27+target%3d%27_blank%27%3Eclick+here.%3C%2fa%3E%22}
it should return "message click here" (and click here is as link to www.linktosomeurl.com)!
as I said - it works fine when just open page. But the problem is that it does not get response message if open the page in fancybox (somehow fancybox jQuery breaks this response message because of the a href url inside it).
is there a way how I can get this response message with url also using Fancybox?
Any hint about the problem would be appreciated...really stuck with this ;-(
Try
var res = "?response={%22Message%22%3a%22response+message+%3Ca+href%3d%27http%3a%2f%2fwww.linktosomeurl.com%27+target%3d%27_blank%27%3Eclick+here.%3C%2fa%3E%22}";
var response = $.parseHTML(decodeURIComponent(res.split(/\=\{|\}/)[1]).replace(/response|message|\+/gi," "))[1];
$("body").append(response)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
so far not find the solution, but used workaround, more flexible than answered before - asked external site owners to change response message use link as plain text, and at my side change plain text link to a href link as described here:
How to replace plain URLs with links?
so far works fine! Not real solution, but quite good workaround to save time...
thanks for hints, suggestions to all! ;-)
Related
I'm trying my hardest to properly implement my system with the Last.fm API, but I just cannot get it to work.
I am supposed to redirect the user to https://www.last.fm/api/auth?api_key=<API KEY>&cb=<CALLBACK>", which works perfectly fine as long as the user actually signs in. But if the user presses Cancel, you just end up at https://www.last.fm/api/None instead of the callback. Docs can be found here.
I tried to look into how other sites did it like openscrobbler.com, but the source code is unfortunately of no help. They also simply set the window's href to the right url with the same parameters as I do (logIn function here).
Alternatively I tried using a pop up window but that's also to no avail because I cannot access any of the data inside of the popup (CORS) and none of the events I tried (unload, beforeunload, close, ..) work.
Code I tried to redirect:
window.location.href = `https://www.last.fm/api/auth/?api_key=${api.lastFmApiKey}&cb=https://example.com/`;
And for the pop-up:
const popup = window.open(url, "Last.fm Login", `popup width=${loginWindowWidth}, height=${loginWindowHeight}, left=${left}, top=${top}`);
Any help with either getting the redirections to go right or a trick to get information from the popup window (when redirected specifically so I know when they are on the None page), would be greatly appreciated.
Thank you!
It is just that, I have a button that opens the website, but I can't figure out how to fill that field on that website and search for the String that I'm providing.
I really don't know where to look for this.
Right now, I open the website with :window.open(url); but that's it.
Using console, I can fill the txtInput using this $('#txtBuscar').val('geo');
Then click the button with this: $('#btnBuscar').click();
But I don't know how to do this from my function...
Any ideas on what to use?
Website is https://www.mercadopublico.cl/Home
You cannot do this without getting a Cross-Origin Resource Sharing (CORS) error.
Unless the site you are accessing allows it, you cannot access the code.
See How does Access-Control-Allow-Origin header work? for a full explanation.
I think you can't do that. Because when you use window.open(url); the browser opens a new window with url, but you script will be running in the previous window.
You could have the new site open up in an iframe on your page and then navigate the dom with your pages javaScript.
I'm working in writing a chrome extension, and as a result I have the peculiar situation of using non-cross domain Iframes, without the ability to alter the page being displayed in the frame.
When a user clicks a certain link, in he iframe, I want to run some JavaScript. The default behavior for clicking that link is to load page targetpage.com. I don't think it's possible, or easy, to read listen for a particular element being clicked inside an iframe
As a workaround, I figure I can check if the iframe reloads, pointing to targetpage.com, and then perform the action.
Note: the action is entirely in the parent page, let's imagine I'm just trying to trigger an alert box.
I know how to trigger JavaScript when an iframe loads. My three questions are:
1) how can I check the url of an iframe?
2) is there a way to check the iframe, url prior to targetpage.com being loaded. Esther than after?
3) is there a better solution?
You could listen to webNavigation.onBeforeNavigate in background page, it fires when a navigation is about to occur, and you could get url and frameId in the callback parameter.
This may not be the best answer because I haven't played around with this much.
Chrome has a webNavigation API that looks to be something which may come in handy for your extension.
However if you want to get the current domain you're on you'd use...
document.domain
If you're in a subdirectory of that domain you can grab that with...
window.location
It also works with an added hash to the url.
If you want the url without the hash you could use document.referrer or if you feel hacky you could do something like...
var str = window.location
var res = str.toString().split(str.hash)
document.body.innerHTML = res
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'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