I know a way to solve this but it's the wrong way and involves creating a new file and simply cheat.
Now the problem:
i have a folder with the index.html file; this file has a menu which has a <a href="reg_interlocutor.html">
in reg_interlocutor.html i use div's and in one of them i call the registration form:
this inserts the content of file form_registo_interlocutor.html into the div and sends the data inserted by the user to the file reg_interlocutor.php inside a folder called php;
in this file reg_interlocutor.php, when there is a problem with the data i use
echo "<script>alert('blablabla.'); window.location = '../index.html';</script>";
But if everything goes ok, i want to reload index.html.
The problem is that the browser reloads index.html inside the same div i was using since Step 2.
Actually, the tab url stays the same: localhost/proj/reg_interlocutor.html every step since step_2.
I already used:
header('window-target: main');
header('location:../index.html');
<script>top.window.location='../index.html';</script>
window.open("http://localhost/proj/index.html","_self");
Can anyone help me? I understand that my code is stuck on the div and that is why the index file is open inside that div.
You would probably be better off by using PHP (instead of HTML) to include an external html file instead of doing this directly in HTML. PHP can inject the external HTML file into the final output, which results in a much cleaner result than having the user's web browser fetch the other html file (creating a second request). This should also resolve the html loading into the <object> tag instead of the full page.
Related
I am fetching the HTML code from some external API. On my website, I want to create an anchor, which will open a new tab showing that HTML code parsed. How can I do that?
One way I know of is to just make an iframe, and show the code there, but that won't open a new tab and won't adjust the size easily.
What's the best way to solve this? I am using node.js express as a website's server.
you could use window.open("your url here") javascript function. You could just use an onclick attribute to call it like below:
<span onclick='window.open("your url here")'>view</span>
after which you could replace contents of a tag (lets say the body tag) with the html code received from the external API with standard javascript
I have a php file that loads a different form based on a identifier passed in with a GET request.
Everything works.... except my Javascript/jQuery. Is there a way to re-load my javascript to get it to work on the form?
Or will I need to something else entirely ? like a template system?
Currently, when the page is being loaded by the browser it is commenting out my Javascript script tag that loads my functions.js file. I'm assuming this is because it is because the code relies on a form and as the form hadn't been loaded yet, some kind of error forces the script to be commented out.
You can rectify your problem in two ways:-
1. Put you complete javascript/jQuery code at the bottom of the page (very last) inside (<script></script>)
Or
2. Wrap your complete code inside $(document).ready(function(){ ...//your code ....});
Note:-
a. If you are trying to include an external javascript/jQuery file which have the custom code,then also include it at the bottom of the current page.
b. Take care that proper jquery library (if needed) will added before your code
Now I have a lightbox that only can use to show its <div> in current file . Is it possible to use a lightbox to show something from another file.
This is where my lightbox linked to <a id="list" href="?lightbox[width]=808&lightbox[height]=365#div_currentfile" class="lightbox">Change Password</a>
and the example file I want to open up from my lightbox is test_lightbox.php
any help will be appriciated
There are two ways to achieve this:
Load your php file inside your div using AJAX call by providing the relative path of test_lightbox.php
Put an IFrame inside your div and load that .php file in IFrame.
First method is best if you are trying to load the php file from the same domain. If test_lightbox.php file is served from some other place, then second method is the right choice.
If you are not sure how to load, have a look in the following url. But without jQuery also you can acheive the result.
jQuery Load
I'm trying to reload an entire page with a jQuery AJAX request (supplying a simple GET parameter to the load), roughly in this fashion.
$.ajax({
url: "site.php?param="+new_param,
cache: false,
success: function(content) {
$("html").html(content);
}
});
As you can see, this will cascade the <html> blocks and somehow the styling gets broken (background is suddenly white and so on).
Tricks like $(document).html(content); won't work either.
Unfortunately I haven't found any solution to this problem, yet.
If you are not reloading head content (loading new javascript or css), and I see no reason why you should do such a thing, you should really try to contain your content loading to content itself, ie. <body>.
$("body").html(content);
Edit
In order to achieve, what I think you are trying to, you could check out https://github.com/defunkt/jquery-pjax
The problem with loading a full HTML page is that you only get the HTML code but the JavaScript is not interpreted, and the paths to the CSS files get messed up.
Imagine if you will: you are inside the index.php file and the CSS files are located in the same directory. Now if you load a different HTML file using AJAX, and output that code inside a div, maybe that file points to the "../css/random_dir/style.css" file. Now that path is not good inside your index.php file, and that's why the styling gets messed up.
Your new code would expect to find the "background" inside a css file that is not loaded (and will not be loaded).
Is there a way to load the entire contents of a page into a javascript variable? (the page is not properly formatted HTML.) Ie store the page contents as a string in a variable. It only needs to work with Firefox.
I have some javascript running in one firefox tab that accesses the content of a page in another tab (the target window). Normally the content of the target is an HTML page so I can get at its content like this...
targetWindowName.document.getElementsByTagName("html")[0].innerHTML;
However I have come across a page that is not in proper HTML and so the above doesnt work.
(The actual content of this awkward page is JSON. I know this would be best loaded up with AJAX or something but I have a framework already setup to process HTML pages and it would be very handy if I can treat this particular (one off) page just like a regular HTML page.)
Thanks
Guess you can use:
win.document.documentElement.innerHTML
Read the file into a variable. Like you would any text file.
So, Page "A" has code that goes out and gets the HTML page contents and loads it into a variable.