I have a page which is part of Cache manifest (/cache).
As soon as my application is offline mode, I can open that page (http://app/cache). But if I try to access it with query string, Chrome treat it as Non-Existing and return fallback page (http://app/cache?url=1234 - does not work).
Does anyone know workaround for that?
I would use # - has tag to pass parameters. Like this:
http://app/cache#url/1234
Browsers ignores the hashtag, but your page javascript can parse and act on it.
It should be true that you will not be opening a page by tying the url on the browser. You will be clicking on a page to open the page. So on click call a Javascript function. Pass the querystring value to the function. save the querystring value to localstorage with a name.
When the page opens up read this value from localstorage on page load and get the value and use in your page.
Related
This is an MVC razor page, that works fine on first load.
If I use a reload from javascript or even a refresh in the browser menu (Chrome), I get
Server Error in '/' Application.
>The view 'actionChangeUserSentence' or its master was not found or no view
>engine supports the searched locations. The following locations were searched:
>~/Views/Conduct/actionChangeUserSentence.aspx
>~/Views/Conduct/actionChangeUserSentence.ascx
>~/Views/Shared/actionChangeUserSentence.aspx
>~/Views/Shared/actionChangeUserSentence.ascx
>~/Views/Conduct/actionChangeUserSentence.cshtml
>~/Views/Conduct/actionChangeUserSentence.vbhtml
>~/Views/Shared/actionChangeUserSentence.cshtml
>~/Views/Shared/actionChangeUserSentence.vbhtml
> and so on...
meaning the url string is considered a non MVC url.
I tried several possibilities to reload, including:
-location.reload();
-window.location.reload(false); with both false and true
-location.href = location.href;
-history.go(0);
By the way, the reason I need to refresh is that js drawing on a html canvas doesn't work except after full page (re)load, reason still unknown. But anyway, a browser menu refresh should of course always work, I guess...
Thanks for any help.
I will suggest put that code in on ready function of drawing canvas may this will help you
Use just an Response.Redirect("/<your page>");
Is it possible to have a print option that bypasses the print dialog?
I am working on a closed system and would like to be able to pre-define the print dialog settings; and process the print as soon as I click the button.
From what I am reading, the way to do this varies for each browser. For example, IE would use ActiveX. Chrome / Firefox would require extensions. Based on this, it appears I'll have to write an application in C++ that can handle parameters passed by the browser to auto print with proper formatting (for labels). Then i'll have to rewrite it as an extension for Chrome / Firefox. End result being that users on our closed system will have to download / install these features depending on which browser they use.
I'm hoping there is another way to go about this, but this task most likely violates browser security issues.
I ended up implementing a custom application that works very similar to the Nexus Mod Manager. I wrote a C# application that registers a custom Application URI Scheme. Here's how it works:
User clicks "Print" on the website.
Website links user to "CustomURL://Print/{ID}
Application is launched by windows via the custom uri scheme.
Application communicates with the pre-configured server to confirm the print request and in my case get the actual print command.
The application then uses the C# RawPrinterHelper class to send commands directly to the printer.
This approach required an initial download from the user, and a single security prompt from windows when launching the application the first time. I also implemented some Javascript magic to make it detect whether the print job was handled or not. If it wasn't it asks them to download the application.
I know this is a late reply, but here's a solution I'm using. I have only used this with IE, and have not tested it with any other browser.
This Sub Print blow effectively replaces the default print function.
<script language='VBScript'>
Sub Print()
OLECMDID_PRINT = 6
OLECMDEXECOPT_DONTPROMPTUSER = 2
OLECMDEXECOPT_PROMPTUSER = 1
call WB.ExecWB(OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER,1)
End Sub
document.write "<object ID='WB' WIDTH=0 HEIGHT=0 CLASSID='CLSID:8856F961-340A-11D0-A96B-00C04FD705A2'></object>"
</script>
Then use Javascript's window.print(); ties to a hyperlink or a button to execute the print command.
If you want to automatically print when the page loads, then put the code below near tag.
<script type="text/javascript">
window.onload=function(){self.print();}
</script>
I am writing this answer for firefox browser.
Open File > Page Setup
Make all the headers and footers blank
Set the margins to 0 (zero)
In the address bar of Firefox, type about:config
Search for print.always_print_silent and double click it
Change it from false to true
This lets you skip the Print pop up box that comes up, as well as skipping the step where you have to click OK, automatically printing the right sized slip.
If print.always_print_silent does not come up
Right click on a blank area of the preference window
Select new > Boolean
Enter "print.always_print_silent" as the name (without quotes)
Click OK
Select true for the value
You may also want to check what is listed for print.print_printer
You may have to choose Generic/Text Only (or whatever your receipt printer might be named)
The general answer is: NO you cannot do this in the general case but there some cases where you might do it.
Check
http://justtalkaboutweb.com/2008/05/09/javascript-print-bypass-printer-dialog-in-ie-and-firefox/
If you where allowed to do such a thing anyway, it would be a security issue since a malware script could silently sent printing jobs to visitor's printer.
I found a awesome plugin by Firefox which solve this issue. try seamless printing plugin of firefox which will print something from a web application without showing a print dialog.
Open Firefox
Search addon name seamless printing and install it
After successful installation the printing window will get bypassed when user wants to print anything.
I was able to solve the problem with this library: html2pdf.js (https://github.com/eKoopmans/html2pdf.js)
Considering that you have access to it, you could do something like that (taken from the github repository):
var element = document.getElementById('element-to-print');
html2pdf(element);
i wonder if there is some way to do something like that:
If im on a specific site i want that some of javascript files to be loaded directly from my computer (f.e. file:///c:/test.js), not from the server.
For that i was thinking if there is a possibility to make an extension which could change HTML code in a response which browser gets right before displaying it. So whole process should look like that:
request is made
browser gets response from server
#response is changed# - this is the part when extension comes in
browser parse changed response and display page with that new response.
It doesnt even have to be a Chrome extension anyway. It should just do the job described above. It can block original file and serve another one (DNS/proxy?) or filter whole HTTP traffic in my computer and replace specific code to another one of matched response.
You can use the WebRequest API to achieve that. For example, you can add a onBeforeRequest listener and redirect some requests:
chrome.webRequest.onBeforeRequest.addListener(function(details)
{
var responseData = "<div>Some text</div>"
return {redirectUrl: "data:text/html," + encodeURIComponent(responseData)};
}, {urls: ["https://www.google.com/"]}, ["blocking"]);
This will display a <div> element with the text "some text" instead of the Google homepage. Note that you can only redirect to URLs that the web server itself is allowed to redirect to. This means that redirecting to file:/// URLs is not possible, and you can only redirect to files inside your extension if these are web accessible. data: and http: URLs work fine however.
In Windows you can use the Proxomitron (proxomitron.info) which is a local proxy that can intercept any page or file being loading into your browser and change it using regular expressions (no DOM parsing) however you want, before it is rendered by the browser.
I'm paginating a list of items, and currently the page listed on page load is set by a GET variable (e.g. www.example.com/page.html?page=2). I want to switch it to ajax, but I'm worried users won't be able to bookmark the page they want to view.
Is there a way I can update the URL without redirecting the page?
Use hash
Your website is www.example.com/page.html
Part I.
When you load page two using ajax add a hash to the url
www.example.com/page.html#page2
You can do that using javascript
window.location.hash = "page2".
Now users can bookmark www.example.com/page.html#page2
part II.
When a user request a page say, www.example.com/page.html#page2
You can read the hash using javascript.
var myHash = window.location.hash
If myHash is empty load the page normally.
If it contains "page2", then load the content of page2.
Yes, with a hash in the url. You can learn more here.
You can also find a nice jquery plugin for that purpose here.
Regards
I created an index page with an iframe, calling srs files. The problem is that the src files are listed in Google etc. Clicking from Google on these "src" files does not load the index file, displaying the basic src file. Is there a way to overcome this?
This is a problem that was more common when a lot of sites used framesets. What you need is a script that detects if the page is opened as the main page, and redirect to the index page if it is, sending it's url along as querystring parameter:
if (window.location.href == window.top.location.href) window.top.location.href = 'index.html?url=' + escape(window.location.href);
In the index page you would have to detect the querystring that is sent to it, and load the page in the iframe:
var url = /url=(.+)/.exec(document.location.search);
if (url.length == 2) {
document.getElementById('IdOfTheIframe').src = url[1];
}
You might consider to incorporate the information in the page instead of using an iframe, that is more common nowadays. If you can't do it on the server side, you could use AJAX to load content into the page.