extract feed url from page in UIWebView - javascript

I'm writing just another feed reader and I want to make it easy to add new feeds, so I implement a UIWebView where you can browse the web and when you hit the Add button the current page should be scanned for rss feed URLs. But I don't get it.
I have no real idea about Javascript and DOM.
But I know you can get the content of a UIWebview with [wv stringByEvaluatingJavaScriptFromString:#"document.body.innerHTML"];.
So I tried #"document.head" but that doesn't work.
Is there a way to get the <head> of the currently displayed webpage with the help of some javascript?
Or even better, can I use javascript to get the actual feed urls?
I want to avoid to do another fetch on the url to get the html and then scan for the feed urls with NSScanner.
I'm looking forward to pushes into the right direction.

instead use "document.all[0].innerHTML". I am sure this will get you complete HTML source of your current web-page, and not just the content between body element. Then try scanning for element.

Related

Is it possible to create an iframe with Javascript that takes over the entire page almost like a URL masking?

So I want an iframe to take over the entirety of the page, with the ability to scroll up and down.
<iframe src="http://IFRAMEURL.COM"></iframe>
Let's say it will get embedded on another website called http://www.ANOTHERSITEURL.com/page1.php
How do I use Javascript to make my iframe containing http://IFRAMEURL.COM take up the entire page of http://www.ANOTHERSITEURL.com/page1.php
So basically it would almost look like domain masking, where you see the page for http://IFRAMEURL but the URL bar shows http://www.ANOTHERSITEURL.com/page1.php
How would I do this with a pure Javascript solution? Also consider that IFRAMEURL.COM will be different than ANOTHERSITEURL.COM
NOTE: So I need a pure javascript solution. A 3rd party user will be using this code on their site to embed my URL. I DON'T have control of anothersiteurl.com/page1.php

javascript that writes in the google chrome url bar

I want to try and right some code that will guess the default ip of a router that you are currently connected to. To do this, i would write a bit of javascript code that would type into the google chrome URL bar and attempt to search it. For instance: it would type 192.168.0.0 , then 192.168.0.1, etc... currently my largest problem with this is that i have no idea how i would write code that would locate and type into the url bar, i could do it with any other user input. How would i do this?
URL bar is not part of the window so you couldn't just locate it using javascript as with DOM elements.
To read and write to URL you could use window.location (more to find here: https://developer.mozilla.org/en-US/docs/Web/API/Window/location).
If you change window.location to another address, it will force browser to load new content, in the same way as reloading a page. Remember that loading new page will probably lead to discarding your javascript code if it was loaded from within the website.
Another way is to use iframe and dynamically change its url, like here: dynamically set iframe src
If you want to make tool that iterates through possible addresses, i would recommend writing it as a Chrome extension. More about it and tutorial are available here: https://developer.chrome.com/extensions

Need to scroll to a specific line in a PDF embedded in html page

I am looking for a solution where in I am able to move to a specific line in a pdf embedded in HTML .
At the moment I am using object tag to display the pdf in html page .
I know by using open parameters I can scroll through a pdf to a specific page but I am unsure how can this be achieved for a particular line navigation .
Open parameters example has been shared in the below mentioned question link but I need some parameter which helps me reach a particular line in PDF may be using some co-ordinates if that's achievable.The requirement is to scroll a PDF to a particular line and only the PDF should get scrolled not the original HTML page.
How to move the scroll bar of the browser on a pdf file with ASP / Javascript?
I can use any of the JQuery PDF viewers as mentioned here :
http://www.jqueryrain.com/2012/09/best-jquery-pdf-viewer-plugin-examples/
in case your solution uses them .
Please note I don't want to move to a particular location in an HTML page as mentioned in below post rather its about navigating to a particular line in a PDF embedded in a page.
How can I scroll to a specific location on the page using jquery?
Any help or leads would be really appreciated .
Thanks in advance.
Create a destination in the PDF file (assuming you are the one generating it) at the appropriate line, and add #destination to the end of the URL
See https://helpx.adobe.com/acrobat/kb/link-html-pdf-page-acrobat.html#OpenaPDFfiletoasetdestination for an explanation on linking to PDF page numbers and destinations.
Assuming you don't have access to a PDF's source, you can open to a page by adding &page=pagenum to the URL as noted at link html pdf page. You may also want to look at this question.

How can I display a non-styled HTML page inside another page?

I'm gathering HTML from a HTML-editor and save in my database. I want to display this data to the user, but I don't know how to do this without the HTML-text being affected by the styling of my page.
Are there any cool libraries around which can help me with this, or is there a very simple way using only HTML tags and/or javascript?
The easiest way to do this is probably simply stuffing your HTML into an iframe.
Have a look at this question if you want to set it as HTML: Set content of iframe .
But I typically simply accept that the contents of the iframe are loaded using a separate request.

General questions about #! hashbang urls and am I using them correctly

I'm in the process of writing a website that includes a reasonably large gallery. First page of the gallery the user will be displayed a bunch of thumbnail images with a url of: website.com/gallery.php
When they click a thumbnail image, if javaScript is turned off it will follow the url in the href and go to a page called gallery.php?img=67. If javaScript is turned on the href click will not execute, instead it will perform an ajax request to display the larger image and some text about it. The url changes to gallery.php#!img=67. The back button will take you back to the thumbnails, pressing f5 will keep the big image displayed with the text. If someone copies the address with the #! and sends it to someone they will get the same image displayed (assuming the receiver has javaScript turned on).
My question is, have I sorted this out correctly for google to index the individual gallery pages? Will google index them twice, once with the ?img=67 and once with the #! and if so is that a bad thing? I'm using javaScript/Ajax to preload the larger images once the thumbnail page is loaded for speed. I've read a lot of backlash against using hasbang ajaxy things recently and wondering if you think can justify using it here?
Google will follow your links and index the ?img=67 pages, and will not index your #! pages, because it can't see those links. You can tell Google about those links by doing the following:
Add <meta name="fragment" content="!"> to the <head> of your document, and
Handle requests for /?_escaped_fragment_= by returning an "HTML Snapshot" of your page that has all your #! links in the <A> tags.
Also, to make the most of this feature, you should also handle requests for /?_escaped_fragment_=img=67 by returning an HTML snapshot page with the big image displayed. Remember, GoogleBot doesn't execute Javascript. Using the #! URL tells Google to retrieve an alternate version of the page (A version where #! has been replaced with ?_escaped_fragment_=) that should render without Javascript.
THe use of #! tags in URLs are in the news recently, with updates to a well known blog.
http://isolani.co.uk/blog/javascript/BreakingTheWebWithHashBangs has a good description of what they are best used for - and when they can be bad. I think your use in a gallery is quite valid.
In short, a URL like http://lifehacker.com/#!5753509/hello-world... is rewritten by Google, and other compatible web-spiders as http://lifehacker.com/?_escaped_fragment_=5753509/hello-world...
Google may index them twice, but you can also use the canonical meta-tag to ensure it knows what the 'official' copy is.
Possible solution (as suggested in http://isolani.co.uk/blog/javascript/BreakingTheWebWithHashBangs) is to use regular links and translate them to #! in the OnClick() event. This ensures that the site displays regular links and not the shitty #!.
It does mean extra work for the server though, since the server needs to support both versions (the Ajax version and the regular version), but I think it worth it.These #! are so ugly..

Categories