Pull parent page url to chrome extension in iframe - javascript

I have some JavaScript code that returns the current visited page's url. This code runs as a href link. I would like to make it do the same when I open it using a Chrome extension that opens a page in an iframe (can be different domain). The iframe opens fine but the url does not populate. I have tried window.parent.location types to no avail.
javascript:void(window.open('http://www.example.com/..?s=%20'
+encodeURIComponent(document.title)+'%20'
+encodeURIComponent(location.href)+'%20'
+encodeURIComponent(window.getSelection())))

Related

How to check if url-redirection occured

My tool can display external websites in an iFrame.
Few sites (e.g. "http://ec.asm.org/") are loading in my iFrame but after few seconds reloads on the same browser's tab but not as iFrame.
I suspects that it happens because the destination websites changing their location (redirection) to the same url during the page load (onLoad).
Is there way to verify this assumption (redirection to the same page)?
Is there any other possible reason for this problem (iFrame closed)?

How to open a Firefox WebExtension options page as a tab, separate from about:addons

So, I've looked through the WebExtensions API, but I haven't been able to figure out how to open an HTML page separate from about:addons for options. In the Add-on SDK you could have resource://ext-id-/path/to/file.html. I've tried making a directory web accessible and putting an HTML file in there, but that didn't seem to work.
Does anyone know how I can open the options HTML file in it's own tab with WebExtensions?
Opening a tab
Options page always in a tab:
If you want your options page to always open in a tab, you can add the property open_in_tab with a value of true to the options_ui key in your manifest.json:
"options_ui" : {
"page": "options.html",
"open_in_tab":true
}
This will result in your options page always opening in a tab. Both clicking on your extension's "Options" from within about:addons and using runtime.openOptionsPage() will result in your options page opening in a tab.
Thanks to BigBlutHat for reminding me of this option.
In a tab when normally your options page is within about:addons:
You can open a new tab with whatever URL from within your extension you desire, including your options page, using tabs.create and runtime.getURL. Specifically for an options.html file located in the same directory as your manifest.json, the following works:
chrome.tabs.create({
url: chrome.runtime.getURL('/options.html')
});
Does not need to be web accessible and loading JavaScript:
You do not need the files to be declared as web accessible. The page runs in the background context so JavaScript is loaded by directly including the files in the src of a <script> tag (e.g. <script src="/options.js">). This is the same as you would do for a popup. This answer has an extension that uses the same HTML and JavaScript as both a popup and an options page. It does not, however, actually show opening that page as a tab, but it could be done with the above code.
Resolving Relative URLs:
Both Chrome and Firefox state:
Relative URLs will be relative to the current page within the extension.
Note: For all the different chrome.* API calls, Chrome and Firefox do not always resolve relative URLs in the same way. For example, it is different in each browser for chrome.executeScript().

IFrame should breakout, when a link in the IFrame was clicked

I'm working on a Webapp, which just put a layer over a website (http://mywebapp.com/http://www.example-website.com/).
The Website is embedded in an IFrame, so I don't know when the URL of the Website changed. I'd like the have this behaviour: "When a link was clicked in the IFrame, the IFrame should breakout of my window".
I also created for Chrome and Firefox an extension, that is just an icon, which puts "http://mywebapp.com/" for the current URL in the current selected tab.
Is it possible to achieve this behaviour with an extension?
Ok, I found something called content scripts.
Firefox
Chrome
I hope i can access with these extensions the IFrame, I'll give it a try.

How to access bookmarks page and other chrome urls in an extension?

I'm developing an extension which replaces the new tab page with a set of other features.
I have a link on the new "new tab" page. And I've set the value of its href attribute to chrome://bookmarks
But whenever I click on it, I get an error message in the console saying "Not allowed to load local resource."
I also tried loading the unpacked extension files and tried it out. But still wasn't able to access the bookmarks page. I've seen many extensions which have links that can access the bookmarks page. For example, Dayboard.
How do I go about this problem?
You should be able to open chrome://bookmarks/ programmatically.
Make an click handler that triggers chrome.tabs.create({url: "chrome://bookmarks/"}) - I just checked and it works from a background page.
If you need to replace your current tab, use chrome.tabs.update.

prevent html page from open a new window

I have a html based application and sometimes my html app needs to open another url in iframe.
the problem is that the third party url in the iframe open a new window too with the same content, the same url.
so how can i prevent it?
This seems like an iframe breakoutscript in the thirdparty page. A few links about a solution to this problem.
http://stuntsnippets.com/prevent-iframe-breakout/
http://www.zimbio.com/Web+Design/articles/1110/How+prevent+iFrame+breakaway
How to prevent IFRAME from redirecting top-level window

Categories

Resources